﻿using System;
using System.Collections.Generic;

namespace NCP.Infrastructure.Common.Singleton
{
    public class SingletonManager
    {
        static SingletonManager()
        {
            allSingletons = new Dictionary<Type, object>();
        }

        static readonly IDictionary<Type, object> allSingletons;

        public static IDictionary<Type, object> AllSingletons
        {
            get
            {
                return allSingletons;
            }
        }
    }

    public class SingletonManager<T> : SingletonManager
    {
        static T instance;

        public static T Instance
        {
            get
            {
                return instance;
            }
            set
            {
                instance = value;
                AllSingletons[typeof(T)] = value;
            }
        }
    }
}
